#include "SettingsChildWidget.h"
#include "ui_SettingsChildWidget.h"
#include "smartphone/Smartphone.h"
#include <QFileDialog>
#include <QFile>
#include <QMessageBox>
#include <QTextStream>
#include <QTextCodec>
SettingsChildWidget::SettingsChildWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SettingsChildWidget)
{
    ui->setupUi(this);
    modelAudioCodecs = new QStandardItemModel(this);
    QVector<QString> vtVideoDevices = Smartphone::getInstance()->getVideoDevices();
    for(int i = 0; i < vtVideoDevices.size(); i++)
    {
        ui->comboVideo->addItem(vtVideoDevices.at(i), 0);
    }
    QVector<QString> vtAudioCodecs = Smartphone::getInstance()->getCodecs(CodecTypeAudio);
    int size = vtAudioCodecs.size();
    QStandardItem *item;
    for(int i = 0; i < size ; i++)
    {
        item = new QStandardItem(vtAudioCodecs.at(i));
        item->setCheckable(true);

        modelAudioCodecs->appendRow(item);
    }
    ui->lvAudioCodec->setModel(modelAudioCodecs);
}

SettingsChildWidget::~SettingsChildWidget()
{
    delete ui;
}


void SettingsChildWidget::on_comboVideo_currentIndexChanged(int index)
{
    Smartphone::getInstance()->setVideoDevice(index);

}

void SettingsChildWidget::on_btnOpenFile_clicked()
{
    QString path = QFileDialog::getOpenFileName(this,
                                                tr("Open File"),
                                                ".",
                                                tr("Text Files(*.jpg)"));
    ui->edtFile->setText(path);
    Smartphone::getInstance()->setStaticPicture(path);

}
